home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
United Public Domain Gold 2
/
United Public Domain Gold 2.iso
/
utilities
/
pu634.dms
/
pu634.adf
/
GENIES
/
PieChart.pdrx
< prev
next >
Wrap
Text File
|
1994-09-06
|
12KB
|
417 lines
/*
Copyright 1992 StarTeck. All rights reserved.
This Genie will create a pie chart !!!
Just answer the prompts.
*/
call pdm_AutoUpdate(0)
cr = '0a'x
numeric digits 5
msg = PDSetup.rexx(2,0) /* set-up librarys */
units = getclip(pds_units)
if msg ~= 1 then exit_msg(msg)
pi2 = 6.28318
call pdm_unselectobj()
/************ MAINLINE *******************/
call GetNumSlices()
call PercentOrDegrees()
If Percent = 1 then
call Percent()
else
call Degrees()
/*trace ?results*/
call GetPieDia()
call GetCenterPie()
call GetColors()
call DrawPie()
call exit_msg()
/* functions functions functions */
/* functions functions functions */
/* functions functions functions */
/*****************************************************************
Prompt for Percent or Degrees */
PercentOrDegrees:
Percent = 'NIL'
PercentDegree = pdm_Inform(3,'Choose input method...','DEGREES','cancel','PERCENT')
if PercentDegree = 1 | PercentDegree = -1 then exit_msg()
if PercentDegree = 0 then Percent = 0
if PercentDegree = 2 then Percent = 1
return /* end of PercentOrDegrees function */
/*****************************************************************
Get Number of Slices */
GetNumSlices:
NumSlices = getclip(NumberOfSlices)
if NumSlices = '' then NumSlicesPrompt = 'Number of slices:'3
else
NumSlicesPrompt = 'Number of slices:'NumSlices
NumSlices = pdm_getform('Input number of slices...',1,NumSlicesPrompt)
if NumSlices = '' then exit_msg()
if ~(datatype(NumSlices,n)) then exit_msg(Invalid entry...)
if NumSlices < 1 then exit_msg('You must have at least one slice...')
Round = NumSlices + .5
NumSlices = trunc(Round)
call SetClip(NumberOfSlices,NumSlices)
return /* end of GetNumSlices function */
/******************************************************************
Get Pie Diameter */
GetPieDia:
MRUdiaClip = getclip(PieDiaClip)
if MRUdiaClip = '' then DiaPrompt = 'DIAMETER:'3
else
DiaPrompt = 'DIAMETER:'MRUdiaClip
Dia = 0
Do while Dia <= 0
Dia = pdm_getform('Input the pie''s diameter...',1,DiaPrompt)
if Dia = '' then exit_msg()
if ~(datatype(Dia,n)) then exit_msg(Invalid entry...)
if Dia <= 0 then
call pdm_Inform(1,'Diameter must be greater than 0...','RETRY')
end /* end do */
rad = (Dia / 2)
call setclip(PieDiaClip,Dia)
return /* end of GetPieDia function */
*****************************************************************
Get Center of pie */
GetCenterPie:
center = PDM_clickellipse("Where do you want the center of the pie?",Rad,Rad)
if center = '' then exit_msg()
XCenter = word(center,1)
YCenter = word(center,2)
return /* end of GetCenterPie function */
/******************************************************************
Get Colors */
GetColors:
UserColors = pdm_Inform(2,'Choose colors with genies help?','YES','NO')
if UserColors = 0 then
call Colors()
return /* end of GetColors function */
/******************************************************************
Draw Pie */
DrawPie:
call pdm_ShowStatus("Working...")
Offset = (pi2 / 4)
Offset2 = (pi2 * .75)
do i = 1 to NumSlices
/************************START OF SLICE*********/
call pdm_InitPlot(XCenter,YCenter,1,1,0,'Slice#'i) /* initiate incremental start-point */
call pdm_PlotLine(0" "0) /* P1 */
/* get P2 coords */
TotalDeg = 0
do j = 1 to (i-1)
Totaldeg = (TotalDeg + DegSlice.j)
end
TotalDeg = (TotalDeg * .0174533) /* pi divided by 180 */
Point2X = cos(TotalDeg) * rad
Point2Y = -sin(TotalDeg) * rad
DegSlice.i.Radians = (DegSlice.i * .0174533) /* 1 deg. = .0174533 radians */
if DegSlice.i.Radians > 1.5707963 then do
TanLength = (.3516051 * (1.5707963 * rad)) /* Get length of radius */
Tan1X = cos(Offset + TotalDeg) * TanLength
Tan1Y = -sin(Offset + TotalDeg) * TanLength
call pdm_PlotBezier(Point2X" "Point2Y" "0 0 Tan1X Tan1Y)
TotalDeg = TotalDeg + 1.5707963
Do while DegSlice.i.Radians > 1.5707963
InterPX = cos(TotalDeg) * rad
InterPY = -sin(TotalDeg) * rad
TanLength = (.3516051 * (1.5707963 * rad)) /* Get length of radius */
InterTan1X = cos(Offset2 + TotalDeg) * TanLength
InterTan1Y = -sin(Offset2 + TotalDeg) * TanLength
DegSlice.i.Radians = (DegSlice.i.radians - 1.5707063)
if DegSlice.i.Radians < 1.5707963 then /* look ahead */
TanLength = (.3516051 * (DegSlice.i.radians * rad))
InterTan2X = cos(Offset + TotalDeg) * TanLength
InterTan2Y = -sin(Offset + TotalDeg) * TanLength
call pdm_PlotBezier(InterPX" "InterPY" "InterTan1X InterTan1Y InterTan2X InterTan2Y)
if DegSlice.i.Radians > 1.5707963 then
TotalDeg = TotalDeg + 1.5707963
End /* do loop */
End /* if do */
Else do
TanLength = (.3516051 * (DegSlice.i.radians * rad))
Tan1X = cos(Offset + TotalDeg) * TanLength
Tan1Y = -sin(Offset + TotalDeg) * TanLength
call pdm_PlotBezier(Point2X" "Point2Y" "0 0 Tan1X Tan1Y)
End /* if else do*/
/* get P3 coords */
TanLength = (.3516051 * (DegSlice.i.radians * rad))
Totaldeg = (TotalDeg + DegSlice.i.radians)
Point3X = cos(TotalDeg) * rad
Point3Y = -sin(TotalDeg) * rad
Tan2X = cos(Offset2 + TotalDeg) * TanLength
Tan2Y = -sin(Offset2 + TotalDeg) * TanLength
call pdm_PlotBezier(Point3X" "Point3Y" " Tan2X Tan2Y 0 0)
If UserColors = 0 then
call SetFillPattern(,1,ColorSlice#.i,,,,,)
call SetLineJoin(,3)
call SetLineWeight(,.5)
/* call SetLinePattern(0,) */
/* call SetLineColor(,rgb 15,15,15) */
call pdm_ClosePlot()
end
return /* end of DrawPie function */
/*****************************************************************
Create Color list */
Colors:
colorlist = GetColorList()
if ~(colorlist = '') then do
count = 1
pos = index(colorlist, cr)
do while pos > 0
count = count + 1
pos = index(colorlist, cr, pos + 1)
end
end
else
exit_msg(Color palatte not found)
Do i = 1 to NumSlices
ColorSlice#.i = SelectFromList('Choose slice # 'i' color...',30,count,2,colorlist)
if ColorSlice#.i = '' then exit_msg()
end /* end do */
return /* end of Colors function */
/*****************************************************************
Get Percent of Slices */
Percent:
/* Next three lines for testing only */
/*PercentSlice.1 = 10
PercentSlice.2 = 30
PercentSlice.3 = 60
*/
TotalPercentCorrect = '1'
Do while ~(TotalPercentCorrect = 0) /* build percent list from scratch */
MRU = GetClip(SliceClip#.1)
if MRU = '' then do /* MRU most resently used */
PercentPrompt = 'Slice #1'
do i = 2 to (NumSlices-1)
PercentPrompt = PercentPrompt ||cr|| 'Slice #'i
end /* do */
if NumSlices > 1 then
PercentPrompt = PercentPrompt ||cr|| 'Slice #'NumSlices
end /* if then */
else do /* build percent list from MRU clips */
Percent#. = 'empty'
Percent#.1 = GetClip(SliceClip#.1)
Percent#.1 = (Percent#.1 / 3.6) /* convert degrees to percent */
PercentPrompt = 'Slice #1:'Percent#.1
do i = 2 to (NumSlices-1)
Percent#.i = GetClip(SliceClip#.i)
If Percent#.i ~= '' then
Percent#.i = (Percent#.i / 3.6) /* convert degrees to percent */
PercentPrompt = PercentPrompt ||cr|| 'Slice #'i':'Percent#.i
end
if NumSlices > 1 then do
Percent#.NumSlices = GetClip(SliceClip#.NumSlices)
If Percent#.NumSlices ~= '' then
Percent#.NumSlices = (Percent#.NumSlices / 3.6) /*convert degrees to percent */
PercentPrompt = PercentPrompt ||cr|| 'Slice #'NumSlices':'Percent#.NumSlices
end /* if then */
end /* if else */
Percent = ''
Percent = pdm_getform('Input the Percent of each slice...',7,PercentPrompt)
if Percent = '' then exit_msg()
TotalSlicePercent = 0
PercentSlice. = 'empty'
do i = 1 to NumSlices
parse var Percent PercentSlice.i (cr) Percent
if ~(datatype(PercentSlice.i,n)) then exit_msg(Invalid entry...)
if PercentSlice.i < 0 then exit_msg('Percent must be greater than 0...')
TotalSlicePercent = TotalSlicePercent + PercentSlice.i
DegSlice.i = (PercentSlice.i * 3.6) /* convert to degrees */
call SetClip(SliceClip#.i,DegSlice.i)
end
if ~(TotalSlicePercent = 100) then do
PercentCorrectPrompt = 'All your slices added together equal 'TotalSlicePercent' Percent! Is this correct?'
/* 'Is this correct?' */
TotalPercentCorrect = pdm_Inform(2,PercentCorrectPrompt,'YES','NO RE-INPUT')
end /* if then */
else
TotalPercentCorrect = 0
end /* do while */
return /* end of Percent function */
/*****************************************************************
Get Degrees of Slices */
Degrees:
/* Next three lines for testing only */
/*DegSlice.1 = 180
DegSlice.2 = 45
DegSlice.3 = 80
*/
TotalDegCorrect = '1'
Do while ~(TotalDegCorrect = 0)
MRU = GetClip(SliceClip#.1)
if MRU = '' then do /* MRU most resently used */
DegreesPrompt = 'Slice #1'
do i = 2 to (NumSlices-1)
DegreesPrompt = DegreesPrompt ||cr|| 'Slice #'i
end /* do */
if NumSlices > 1 then
DegreesPrompt = DegreesPrompt ||cr|| 'Slice #'NumSlices
end /* if then */
else do
Deg#. = 'empty'
Deg#.1 = GetClip(SliceClip#.1)
DegreesPrompt = 'Slice #1:'Deg#.1
do i = 2 to (NumSlices-1)
Deg#.i = GetClip(SliceClip#.i)
DegreesPrompt = DegreesPrompt ||cr|| 'Slice #'i':'Deg#.i
end
if NumSlices > 1 then do
Deg#.NumSlices = GetClip(SliceClip#.NumSlices)
DegreesPrompt = DegreesPrompt ||cr|| 'Slice #'NumSlices':'Deg#.NumSlices
end /* if then */
end /* if else */
Degrees = ''
Degrees = pdm_getform('Input the degrees of each slice...',7,DegreesPrompt)
if Degrees = '' then exit_msg()
TotalSliceDeg = 0
DegSlice. = 'empTy'
do i = 1 to NumSlices
parse var Degrees DegSlice.i (cr) Degrees
if ~(datatype(DegSlice.i,n)) then exit_msg(Invalid entry...)
if DegSlice.i < 0 then exit_msg('Degrees must be greater than 0...')
TotalSliceDeg = TotalSliceDeg + DegSlice.i
call SetClip(SliceClip#.i,DegSlice.i)
end
if ~(TotalSliceDeg = 360) then do
DegCorrectPrompt = 'All your slices added together equal 'TotalSliceDeg' degree(s)! Is this correct?'
/* 'Is this correct?' */
TotalDegCorrect = pdm_Inform(2,DegCorrectPrompt,'YES','NO RE-INPUT')
end /* if then */
else
TotalDegCorrect = 0
end /* do while */
return /* end of Degrees function */
exit_msg:
do
parse arg message
if message ~= '' then
call pdm_Inform(1, message,)
call pdm_ClearStatus()
call pdm_SetUnits(units)
call pdm_AutoUpdate(1)
exit
end